package com.gemcoder.system.service;

import static com.gemcoder.system.datasource.JdbcTemplateUtil.executeSQL;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Service;
import static com.gemcoder.system.service.UserSdkService.sdkOfGetCurrentUserName;
import static com.gemcoder.system.service.UserSdkService.sdkOfGetCurrentUserId;
import com.gemcoder.system.bo.Result;
import static com.gemcoder.system.service.permission.PermissionSdkService.sdkOfgetAllPermissions;
import static com.gemcoder.system.service.permission.PermissionSdkService.sdkOfgetAllMenus;
import java.sql.SQLException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import cn.hutool.core.util.StrUtil;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.StringJoiner;
import cn.hutool.core.util.StrUtil;
import java.time.LocalDate;
import java.util.Date;

@Service
public class InformationoverviewService {

    public Result addProject(Map<String, Object> paramMap) {
        // 获取当前登录用户的名称
        String createUsername = sdkOfGetCurrentUserName();
        // 获取当前时间
        String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        Integer id = paramMap.get("id") != null ? Integer.valueOf(String.valueOf(paramMap.get("id"))) : null;

        // 获取参数
        List<Object> params = new ArrayList<>();
        params.add(paramMap.get("ProjectNamevalue2") != null ? String.valueOf(paramMap.get("ProjectNamevalue2")) : null);
        params.add(paramMap.get("Watersourcevalue1") != null ? String.valueOf(paramMap.get("Watersourcevalue1")) : null);
        params.add(paramMap.get("ProjectLocationvalue1") != null ? String.valueOf(paramMap.get("ProjectLocationvalue1")) : null);
        params.add(paramMap.get("Billingmethodvalue2") != null ? String.valueOf(paramMap.get("Billingmethodvalue2")) : null);
        params.add(paramMap.get("StartDatevalue1") != null ? String.valueOf(paramMap.get("StartDatevalue1")) : null);
        params.add(paramMap.get("ProjectStatus1value1") != null ? String.valueOf(paramMap.get("ProjectStatus1value1")) : null);
        params.add(paramMap.get("OperationDirectorvalue1") != null ? String.valueOf(paramMap.get("OperationDirectorvalue1")) : null);
        params.add(paramMap.get("ContactInformationvalue1") != null ? String.valueOf(paramMap.get("ContactInformationvalue1")) : null);
        params.add(paramMap.get("FBOXAccountNumbervalue1") != null ? String.valueOf(paramMap.get("FBOXAccountNumbervalue1")) : null);
        params.add(paramMap.get("FBOXTokenvalue1") != null ? String.valueOf(paramMap.get("FBOXTokenvalue1")) : null);
        params.add(paramMap.get("FBOXKeyvalue1") != null ? String.valueOf(paramMap.get("FBOXKeyvalue1")) : null);
        params.add(paramMap.get("BaselineOnRatevalue1") != null ? String.valueOf(paramMap.get("BaselineOnRatevalue1")) : null);
        params.add(paramMap.get("SafetyQualityvalue1") != null ? String.valueOf(paramMap.get("SafetyQualityvalue1")) : null);
        params.add(paramMap.get("Laborcostvalue1") != null ? String.valueOf(paramMap.get("Laborcostvalue1")) : null);
        params.add(paramMap.get("DrugInformationvalue1") != null ? String.valueOf(paramMap.get("DrugInformationvalue1")) : null);
        params.add(paramMap.get("Referencewaterintakevalue1") != null ? String.valueOf(paramMap.get("Referencewaterintakevalue1")) : null);
        params.add(paramMap.get("Electricityunitpricevalue1") != null ? String.valueOf(paramMap.get("Electricityunitpricevalue1")) : null);
        params.add(paramMap.get("Benchmarktonofwaterrunningcostvalue1") != null ? String.valueOf(paramMap.get("Benchmarktonofwaterrunningcostvalue1")) : null);
        params.add(paramMap.get("WaterQuantityConfirmationSheetvalue1") != null ? String.valueOf(paramMap.get("WaterQuantityConfirmationSheetvalue1")) : null);
        params.add(paramMap.get("baselinewateryieldvalue1") != null ? String.valueOf(paramMap.get("baselinewateryieldvalue1")) : null);
        params.add(paramMap.get("Unitpriceofwaterchargevalue1") != null ? String.valueOf(paramMap.get("Unitpriceofwaterchargevalue1")) : null);
        params.add(paramMap.get("Billingunitpricevalue1") != null ? String.valueOf(paramMap.get("Billingunitpricevalue1")) : null);

        StringBuilder sql;
        params.add(currentTime); // 更新当前时间
        if (id != null) {
            // 更新逻辑
            sql = new StringBuilder("UPDATE project SET project_name = ?, water_source = ?, project_location = ?, billing_method = ?, start_date = ?, project_status = ?, operation_manager = ?, contact_info = ?, FBOX_account_number = ?, FBOX_token = ?, FBOX_key = ?, baseline_on_rate = ?, safety_quality = ?, labor_cost = ?, drug_info = ?, reference_water_intake = ?, electricity_unit_price = ?, benchmark_ton_of_water_running_cost = ?, water_quantity_confirmation_sheet = ?, baseline_water_yield = ?, unit_price_of_water_charge = ?, billing_unit_price = ?, update_time = ?, update_username = ? WHERE id = ?");
            params.add(createUsername); // 更新用户名
            params.add(id); // 根据传递的id更新

            // 执行更新SQL
            int updateRows = executeSQL(sql.toString(), params.toArray());
            return new Result(updateRows > 0, updateRows > 0 ? "更新项目成功" : "更新项目失败", null);
        } else {
            // 插入逻辑
            sql = new StringBuilder("INSERT INTO project (project_name, water_source, project_location, billing_method, start_date, project_status, operation_manager, contact_info, FBOX_account_number, FBOX_token, FBOX_key, baseline_on_rate, safety_quality, labor_cost, drug_info, reference_water_intake, electricity_unit_price, benchmark_ton_of_water_running_cost, water_quantity_confirmation_sheet, baseline_water_yield, unit_price_of_water_charge, billing_unit_price, create_time, update_time, create_username, update_username) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
            params.add(currentTime); // 更新时间
            params.add(createUsername); // 创建用户名
            params.add(createUsername); // 更新用户名

            // 执行插入SQL
            int insertRows = executeSQL(sql.toString(), params.toArray());
            return new Result(insertRows > 0, insertRows > 0 ? "新增项目成功" : "新增项目失败", null);
        }
    }


    public Result refreshProjectTable(Map<String, Object> paramMap) {
        // 清空项目名称和项目状态
        paramMap.put("ProjectNamevalue1", "");
        paramMap.put("ProjectStatusvalue1", "");
        // 刷新项目表格
        return getProjectsByPage(paramMap);
    }

    public Result searchProjects(Map<String, Object> paramMap) {
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 构建查询SQL
        StringBuilder sql = new StringBuilder("SELECT * FROM project WHERE 1=1");
        List<Object> params = new ArrayList<>();
        if (paramMap.get("ProjectNamevalue1") != null && !paramMap.get("ProjectNamevalue1").toString().isEmpty()) {
            sql.append(" AND project_name LIKE ?");
            params.add("%" + String.valueOf(paramMap.get("ProjectNamevalue1")) + "%");
        }
        if (paramMap.get("ProjectStatusvalue1") != null && !paramMap.get("ProjectStatusvalue1").toString().isEmpty()) {
            sql.append(" AND project_status = ?");
            params.add(String.valueOf(paramMap.get("ProjectStatusvalue1")));
        }
        // 分页查询
        sql.append(" LIMIT ?, ?");
        params.add((current - 1) * pageSize);
        params.add(pageSize);
        // 执行查询SQL
        List<Map<String, Object>> data = executeSQL(sql.toString(), params.toArray());
        // 查询总条数
        StringBuilder countSql = new StringBuilder("SELECT COUNT(*) AS total FROM project WHERE 1=1");
        List<Object> countParams = new ArrayList<>();
        if (paramMap.get("ProjectNamevalue1") != null && !paramMap.get("ProjectNamevalue1").toString().isEmpty()) {
            countSql.append(" AND project_name LIKE ?");
            countParams.add("%" + String.valueOf(paramMap.get("ProjectNamevalue1")) + "%");
        }
        if (paramMap.get("ProjectStatusvalue1") != null && !paramMap.get("ProjectStatusvalue1").toString().isEmpty()) {
            countSql.append(" AND project_status = ?");
            countParams.add(String.valueOf(paramMap.get("ProjectStatusvalue1")));
        }
        List<Map<String, Object>> countResult = executeSQL(countSql.toString(), countParams.toArray());
        Integer total = countResult.get(0).get("total") != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 返回结果
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", data);
        return new Result(true, "查询成功", result);
    }

    public Result getProjectCount(Map<String, Object> paramMap) {
        StringBuilder countSql = new StringBuilder("SELECT COUNT(*) AS total FROM project WHERE 1=1");
        List<Map<String, Object>> countResult = executeSQL(countSql.toString(), null);
        Integer total = countResult.get(0).get("total") != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        return new Result(true, "查询成功", result);
    }

    public Result getAllProjects(Map<String, Object> paramMap) {
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 构建查询SQL
        StringBuilder sql = new StringBuilder("SELECT id, project_name, water_source, project_location, billing_method, start_date, project_status, project_score, operation_manager, contact_info FROM project LIMIT ?, ?");
        List<Object> params = new ArrayList<>();
        params.add((current - 1) * pageSize);
        params.add(pageSize);
        // 执行查询SQL
        List<Map<String, Object>> data = executeSQL(sql.toString(), params.toArray());
        // 查询总条数
        String countSql = "SELECT COUNT(*) AS total FROM project";
        List<Map<String, Object>> countResult = executeSQL(countSql, new Object[] {});
        Integer total = countResult.get(0).get("total") != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 返回结果
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", data);
        return new Result(true, "查询成功", result);
    }

    public Result getProjectsByPage(Map<String, Object> paramMap) {
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 构建查询SQL
        StringBuilder sql = new StringBuilder("SELECT id, project_name, water_source, project_location, billing_method, start_date, project_status, project_score, operation_manager, contact_info FROM project LIMIT ?, ?");
        List<Object> params = new ArrayList<>();
        params.add((current - 1) * pageSize);
        params.add(pageSize);
        // 执行查询SQL
        List<Map<String, Object>> data = executeSQL(sql.toString(), params.toArray());
        // 查询总条数
        String countSql = "SELECT COUNT(*) AS total FROM project";
        List<Map<String, Object>> countResult = executeSQL(countSql, new Object[] {});
        Integer total = countResult.get(0).get("total") != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 返回结果
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", data);
        return new Result(true, "查询成功", result);
    }

    public Result terminateProject(Map<String, Object> paramMap) {
        // 获取当前行数据的项目ID
        Integer projectId = paramMap.get("id") != null ? Integer.valueOf(String.valueOf(paramMap.get("id"))) : null;
        // 构建更新SQL
        StringBuilder sql = new StringBuilder("UPDATE project SET project_status = '终止' WHERE id = ?");
        List<Object> params = new ArrayList<>();
        params.add(projectId);
        // 执行更新SQL
        int updateRows = executeSQL(sql.toString(), params.toArray());
        // 返回结果
        return new Result(updateRows > 0, updateRows > 0 ? "项目终止成功" : "项目终止失败", null);
    }

    public Result deleteDrugData(Map<String, Object> paramMap) {
        // 获取药品ID
        Integer id = paramMap.get("id") != null ? Integer.valueOf(String.valueOf(paramMap.get("id"))) : null;
        if (id == null) {
            return new Result(false, "药品ID不能为空", null);
        }
        // 删除药品数据
        String deleteSql = "DELETE FROM medicine WHERE id = ?";
        int deleteRows = executeSQL(deleteSql, id);
        if (deleteRows > 0) {
            return new Result(true, "删除成功", null);
        } else {
            return new Result(false, "删除失败", null);
        }
    }

    public Result refreshDrugTable(Map<String, Object> paramMap) {
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 查询药品总数
        String countSql = "SELECT COUNT(*) AS total FROM medicine";
        List<Map<String, Object>> countResult = executeSQL(countSql);
        Integer total = countResult.get(0).get("total") != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 查询药品数据
        String dataSql = "SELECT id, medicine_name, unit_price, create_username, create_time, update_username, update_time FROM medicine LIMIT ?, ?";
        List<Object> dataParams = new ArrayList<>();
        dataParams.add((current - 1) * pageSize);
        dataParams.add(pageSize);
        List<Map<String, Object>> dataResult = executeSQL(dataSql, dataParams.toArray());
        // 返回结果
        Map<String, Object> resultData = new HashMap<>();
        resultData.put("total", total);
        resultData.put("data", dataResult);
        return new Result(true, "查询成功", resultData);
    }

    public Result addDrug(Map<String, Object> paramMap) {
        Integer id = paramMap.get("id") != null ? Integer.valueOf(String.valueOf(paramMap.get("id"))) : null;
        // 获取当前登录用户的用户名
        String currentUserName = sdkOfGetCurrentUserName();
        // 从paramMap中获取药品名称和单价
        String drugName = paramMap.get("DrugNamevalue1") != null ? String.valueOf(paramMap.get("DrugNamevalue1")) : null;
        BigDecimal unitPrice = paramMap.get("Unitpriceyuantonvalue1") != null ? new BigDecimal(String.valueOf(paramMap.get("Unitpriceyuantonvalue1"))) : null;
        if (id!= null){
            // 更新药品信息
            StringBuilder updateSql = new StringBuilder("UPDATE medicine SET medicine_name =?, unit_price =?, update_username =?, update_time = NOW() WHERE id =?");
            List<Object> params = new ArrayList<>();
            params.add(drugName);
            params.add(unitPrice);
            params.add(currentUserName);
            params.add(id);
            int updateRows = executeSQL(updateSql.toString(), params.toArray());
            return new Result(updateRows > 0, updateRows > 0? "更新药品成功" : "更新药品失败", null);
        } else {
            // 插入药品信息到medicine表
            StringBuilder insertSql = new StringBuilder("INSERT INTO medicine (medicine_name, unit_price, create_username, create_time, update_username, update_time) VALUES (?, ?, ?, NOW(), ?, NOW())");
            List<Object> params = new ArrayList<>();
            params.add(drugName);
            params.add(unitPrice);
            params.add(currentUserName);
            params.add(currentUserName);
            int insertRows = executeSQL(insertSql.toString(), params.toArray());
            return new Result(insertRows > 0, insertRows > 0 ? "新增药品成功" : "新增药品失败", null);
        }
    }

    public Result refreshDrugTable6LK(Map<String, Object> paramMap) {
        // 获取当前项目ID
        Integer projectId = paramMap.get("projectId") != null ? Integer.valueOf(String.valueOf(paramMap.get("projectId"))) : null;
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 查询项目药品表的总条数
        StringBuilder countSql = new StringBuilder("SELECT COUNT(*) AS total FROM project_medicine pm JOIN medicine m ON pm.medicine_id = m.id WHERE pm.project_id = ?");
        List<Object> countParams = new ArrayList<>();
        countParams.add(projectId);
        List<Map<String, Object>> countResult = executeSQL(countSql.toString(), countParams.toArray());
        Integer total = countResult.get(0) != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 查询项目药品表的数据
        StringBuilder dataSql = new StringBuilder("SELECT pm.id, m.medicine_name AS drugName, pm.unit_price AS unitPrice FROM project_medicine pm JOIN medicine m ON pm.medicine_id = m.id WHERE pm.project_id = ? LIMIT ?, ?");
        List<Object> dataParams = new ArrayList<>();
        dataParams.add(projectId);
        dataParams.add((current - 1) * pageSize);
        dataParams.add(pageSize);
        List<Map<String, Object>> dataResult = executeSQL(dataSql.toString(), dataParams.toArray());
        // 返回结果
        Map<String, Object> resultData = new HashMap<>();
        resultData.put("total", total);
        resultData.put("data", dataResult);
        return new Result(true, "刷新药品表成功", resultData);
    }

    public Result getDrugsList(Map<String, Object> paramMap) {
        // 获取分页参数
        Integer current = paramMap.get("current") != null ? Integer.valueOf(String.valueOf(paramMap.get("current"))) : 1;
        Integer pageSize = paramMap.get("pageSize") != null ? Integer.valueOf(String.valueOf(paramMap.get("pageSize"))) : 10;
        // 查询项目药品表的总条数
        StringBuilder countSql = new StringBuilder("SELECT COUNT(*) AS total FROM medicine");
        List<Map<String, Object>> countResult = executeSQL(countSql.toString(),  null);
        Integer total = countResult.get(0) != null ? Integer.valueOf(String.valueOf(countResult.get(0).get("total"))) : 0;
        // 查询药品表的数据
        StringBuilder dataSql = new StringBuilder("SELECT m.id, m.medicine_name AS drugName, m.unit_price AS unitPrice FROM  medicine m  LIMIT ?, ?");
        List<Object> dataParams = new ArrayList<>();
        dataParams.add((current - 1) * pageSize);
        dataParams.add(pageSize);
        List<Map<String, Object>> dataResult = executeSQL(dataSql.toString(), dataParams.toArray());
        // 返回结果
        Map<String, Object> resultData = new HashMap<>();
        resultData.put("total", total);
        resultData.put("data", dataResult);
        return new Result(true, "获取项目药品表成功", resultData);
    }

    public Result getProjectDetails(Map<String, Object> paramMap) {
        // 获取项目ID
        Integer projectId = paramMap.get("id") != null ? Integer.valueOf(String.valueOf(paramMap.get("id"))) : null;
        if (projectId == null) {
            return new Result(false, "项目ID不能为空", null);
        }
        // 查询项目详情
        StringBuilder projectSql = new StringBuilder("SELECT     id,\n" +
                "    project_name,\n" +
                "    water_source,\n" +
                "    project_location,\n" +
                "    billing_method,\n" +
                "    start_date,\n" +
                "    project_status,\n" +
                "    operation_manager,\n" +
                "    contact_info,\n" +
                "    FBOX_account_number,\n" +
                "    FBOX_token,\n" +
                "    FBOX_key,\n" +
                "    baseline_on_rate,\n" +
                "    safety_quality,\n" +
                "    labor_cost,\n" +
                "    drug_info,\n" +
                "    reference_water_intake,\n" +
                "    electricity_unit_price,\n" +
                "    benchmark_ton_of_water_running_cost,\n" +
                "    water_quantity_confirmation_sheet,\n" +
                "    baseline_water_yield,\n" +
                "    unit_price_of_water_charge,\n" +
                "    billing_unit_price,\n" +
                "    create_time,\n" +
                "    update_time,\n" +
                "    create_username,\n" +
                "    update_username  FROM project WHERE id = ?");
        List<Map<String, Object>> projectResult = executeSQL(projectSql.toString(), projectId);
        if (projectResult == null || projectResult.isEmpty()) {
            return new Result(false, "未找到对应的项目", null);
        }
        Map<String, Object> projectDetails = projectResult.get(0);
        // 查询项目药品信息
        StringBuilder medicineSql = new StringBuilder("SELECT m.medicine_name, pm.unit_price FROM project_medicine pm JOIN medicine m ON pm.medicine_id = m.id WHERE pm.project_id = ?");
        List<Map<String, Object>> medicineResult = executeSQL(medicineSql.toString(), projectId);
        if (medicineResult != null && !medicineResult.isEmpty()) {
            StringBuilder medicineInfo = new StringBuilder();
            for (Map<String, Object> medicine : medicineResult) {
                if (medicineInfo.length() > 0) {
                    medicineInfo.append(", ");
                }
                medicineInfo.append(String.valueOf(medicine.get("medicine_name"))).append(": ").append(String.valueOf(medicine.get("unit_price")));
            }
            projectDetails.put("DrugInformationvalue1", medicineInfo.toString());
        } else {
            projectDetails.put("DrugInformationvalue1", "");
        }
        return new Result(true, "查询成功", projectDetails);
    }

    public Result getStartupProjectCount(Map<String, Object> paramMap) {
        // 构建查询项目状态为开机的项目总数的SQL
        String sql = "SELECT COUNT(*) AS startupCount FROM project WHERE project_status = ?";
        List<Object> params = new ArrayList<>();
        params.add("开机");
        // 执行SQL查询
        List<Map<String, Object>> result = executeSQL(sql, params.toArray());
        // 获取查询结果
        int startupCount = 0;
        if (result != null && !result.isEmpty()) {
            startupCount = Integer.valueOf(String.valueOf(result.get(0).get("startupCount")));
        }
        // 构建返回结果
        Result res = new Result();
        res.setFlag(true);
        res.setMessage("查询成功");
        Map<String, Object> data = new HashMap<>();
        data.put("NumberofStartupvalue1", startupCount);
        res.setData(data);
        return res;
    }

    public Result getShutdownProjectCount(Map<String, Object> paramMap) {
        // 构建查询停机项目数量的SQL
        StringBuilder sql = new StringBuilder("SELECT COUNT(*) AS shutdownCount FROM project WHERE project_status = ?");
        List<Object> params = new ArrayList<>();
        params.add("停机");
        // 执行SQL查询
        List<Map<String, Object>> result = executeSQL(sql.toString(), params.toArray());
        // 构建返回结果
        Result res = new Result();
        res.setFlag(true);
        res.setMessage("查询成功");
        res.setData(result.get(0));
        return res;
    }

    public Result getTotalWaterYield(Map<String, Object> paramMap) {
        // 构建查询总产水量的SQL
        StringBuilder sql = new StringBuilder("SELECT SUM(water_consumption) AS totalWaterYield FROM operational_data WHERE 1=1");
        List<Object> params = new ArrayList<>();
        // 执行SQL查询
        List<Map<String, Object>> result = executeSQL(sql.toString(), params.toArray());
        // 处理查询结果
        Map<String, Object> data = new HashMap<>();
        if (result != null && !result.isEmpty()) {
            data.put("totalWaterYield", result.get(0).get("totalWaterYield"));
        } else {
            data.put("totalWaterYield", 0);
        }
        // 返回结果
        return new Result(true, "查询成功", data);
    }

    public Result getYesterdaysWaterYield(Map<String, Object> paramMap) {
        // 获取昨天的日期
        LocalDate yesterday = LocalDate.now().minusDays(1);
        // 构建查询昨日产水量的SQL
        StringBuilder sql = new StringBuilder("SELECT SUM(water_consumption) AS yesterdaysWaterYield FROM operational_data WHERE date = ?");
        List<Object> params = new ArrayList<>();
        params.add(java.sql.Date.valueOf(yesterday));
        // 执行SQL查询
        List<Map<String, Object>> result = executeSQL(sql.toString(), params.toArray());
        // 处理查询结果
        Map<String, Object> data = new HashMap<>();
        if (result != null && !result.isEmpty()) {
            data.put("yesterdaysWaterYield", result.get(0).get("yesterdaysWaterYield"));
        } else {
            data.put("yesterdaysWaterYield", 0);
        }
        // 返回结果
        return new Result(true, "查询成功", data);
    }
}
